package mgslangpack;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

public class AddMem
{
    public AddMem() throws Exception
    {
        final JFrame f;
        Button b1,b2,b3;
        Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12;
        final TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;        
        f= new JFrame("Add Club Member");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(780,700);
        f.setLayout(null);
        f.setVisible(false);
        Container ctn=f.getContentPane();
        ctn.setBackground(Color.LIGHT_GRAY);
        JLabel Pic;
        Pic=new JLabel(new ImageIcon("braided-wedding-rings.jpg"));
        Pic.setBounds(150,350,480,367);
        ctn.add(Pic);
        Font f1 = new Font("Lucida Handwriting",Font.BOLD,24);
        l1 = new Label("Add new Club members details:");
        l1.setBounds(50,10,500,40);
        l1.setFont(f1);
        f.add(l1);
        l2= new Label("ID Number:");
        l2.setBounds(50,50,100,30);
        f.add(l2);
        tf1=new TextField(); tf1.setBounds( 150,50,150,25); f.add(tf1);
        l3=new Label("Name:");
        l3.setBounds(50,80,100,30);
        f.add(l3);
        tf2=new TextField(); tf2.setBounds( 150,80,150,25); f.add(tf2);
        l4=new Label("Surname:");
        l4.setBounds(350,80,100,30);
        f.add(l4);
        tf3=new TextField(); tf3.setBounds( 450,80,150,25); f.add(tf3);
        l5=new Label("Phone No. (H/W):");
        l5.setBounds(50,110,100,30);
        f.add(l5);
        tf4=new TextField(); tf4.setBounds( 150,110,150,25); f.add(tf4);
        l7= new Label("Cell Number:");
        l7.setBounds(350,110,100,30);
        f.add(l7);
        tf5 = new TextField(); tf5.setBounds( 450,110,150,25); f.add(tf5);
        l8= new Label("E-mail Address:");
        l8.setBounds(50,140,150,30);
        f.add(l8);
        tf6=new TextField(); tf6.setBounds( 150,140,300,25); f.add(tf6);
        l9= new Label("Address");
        l9.setBounds(50,170,100,30);
        f.add(l9);
        tf7=new TextField(); tf7.setBounds( 150,170,200,25); f.add(tf7);
        l10= new Label("Suburb");
        l10.setBounds(50,200,100,30);
        f.add(l10);
        tf8=new TextField(); tf8.setBounds( 150,200,185,25); f.add(tf8);
        l11= new Label("Town");
        l11.setBounds(50,230,100,30);
        f.add(l11);
        tf9 = new TextField(); tf9.setBounds( 150,230,150,25); f.add(tf9);
        l12= new Label("Code");
        l12.setBounds(50,260,100,30);
        f.add(l12);
        tf10=new TextField(); tf10.setBounds( 150,260,100,25); f.add(tf10);
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        final Connection con =
        DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");
        b1=new Button("ADD");
        b1.setBounds(50,290,80,30);
        b1.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;
                    s1=tf1.getText();
                    s2=tf2.getText();
                    s3=tf3.getText();
                    s4=tf4.getText();
                    s5=tf5.getText();
                    s6=tf6.getText();
                    s7=tf7.getText();
                    s8=tf8.getText();
                    s9=tf9.getText();
                    s10=tf10.getText();
                    PreparedStatement ps = con.prepareStatement("insert into Member values(?,?,?,?,?,?,?,?,?,?)");
                    ps.setString(1,s1);
                    ps.setString(2,s2);
                    ps.setString(3,s3);
                    ps.setString(4,s4);
                    ps.setString(5,s5);
                    ps.setString(6,s6);
                    ps.setString(7,s7);
                    ps.setString(8,s8);
                    ps.setString(9,s9);
                    ps.setString(10,s10);
                    int i = ps.executeUpdate();
                    JOptionPane.showMessageDialog(null,"New Club Member Added");
                    tf1.setText("");
                    tf2.setText("");
                    tf3.setText("");
                    tf4.setText("");
                    tf5.setText("");
                    tf6.setText("");
                    tf7.setText("");
                    tf8.setText("");
                    tf9.setText("");
                    tf10.setText("");
                }
                catch(Exception e1)
                {
                    JOptionPane.showMessageDialog(null,"Error On Input Data!");
                }
            }
        }
        );
        f.add(b1);
        b2 = new Button("Back");
        b2.setBounds(640,290,80,30);
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    f.hide();
                }
                catch(Exception e3){}
            }
        }
        );
        f.add(b2);
        b3 = new Button("Exit");
        b3.setBounds(640,30,80,30);
        b3.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    System.exit(0);
                }
                catch(Exception e3){}
            }
        }
        );

        f.add(b3);
        f.show();
    }
}
/******************************************************************************/